﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace ASPItalia.ModelVirtualCasting.WPF.ViewModels.Test
{
    public static class AssertHelper
    {

        public static bool WairFor<T>(T obj, Func<T, Boolean> predicate, TimeSpan timeout)
        {
            Stopwatch s = new Stopwatch();
            s.Start();
            while (!predicate(obj))
            {
                System.Threading.Thread.Sleep(200);
                if (s.Elapsed > timeout)
                    return false;
            }

            return true;
        }

        public static void RunSTA(ThreadStart action)
        {
            Thread t = new Thread(action);
            //t.IsBackground = true;
            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            t.Join();
        }
    }
}
